﻿using DomainService.IService.Sys;
using DomainService.Service.Sys;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;
using Model.BusinessModel;
using Model.BusinessModel.OutPut.sys;
using Model.DomainModel.Sys;
using Utility;

namespace OverallAuth_WebApi.Controllers.Sys
{
    /// <summary>
    /// Sys_MenuTableCols 按钮
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "SysMenuTableCols")]
    public class SysMenuTableColsController : BaseController
    {
        #region 构造实列化

        /// <summary>
        /// 菜单数据列服务
        /// </summary>
        public ISysMenuTableColsService _sysMenuTableColsService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="sysMenuTableColsService"></param>
        public SysMenuTableColsController(ISysMenuTableColsService sysMenuTableColsService)
        {
            _sysMenuTableColsService = sysMenuTableColsService;
        }

        #endregion

        #region 接口

        /// <summary>
        /// 反射同步数据列
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public ReceiveStatus ReflexSynchronousCols()
        {
            var loginUserModel = GetLoginUserMsg();
            return _sysMenuTableColsService.ReflexSynchronousCols(loginUserModel.CorporationKey ?? string.Empty, Const.OverallAuth_SystemKey);
        }

        /// <summary>
        /// 根据菜单id获取列
        /// </summary>
        /// <param name="menuId">菜单ID</param>
        /// <returns></returns>
        [HttpGet]
        public ReceiveStatus<SysMenuTableColsOutPut> GetTableColsByMenuId(string menuId)
        {
            return _sysMenuTableColsService.GetTableColsByMenuId(menuId);
        }


        /// <summary>
        ///  根据条件获取数据列
        /// </summary>
        /// <param name="pageResultModel">分页模型</param>
        /// <returns></returns>
        [HttpPost]
        public ReceiveStatus<SysMenuTableColsOutPut> GetTableColsByWhere(PageResultModel pageResultModel)
        {
            ReceiveStatus<SysMenuTableColsOutPut> receiveStatus = new();
            var result = _sysMenuTableColsService.GetTableColsByWhere(pageResultModel);
            receiveStatus.data = result.data;
            receiveStatus.total = result.total;
            return receiveStatus;
        }

        /// <summary>
        /// 新增数据列
        /// </summary>
        /// <param name="sysMenuTableCols"></param>
        [HttpPost]
        public ReceiveStatus InsertCols(SysMenuTableCols sysMenuTableCols)
        {
            return _sysMenuTableColsService.InsertCols(sysMenuTableCols);
        }

        /// <summary>
        /// 修改字段信息
        /// </summary>
        /// <param name="sysMenuTableCols"></param>
        [HttpPost]
        public ReceiveStatus UpdateTableCols(SysMenuTableCols sysMenuTableCols)
        {
            return _sysMenuTableColsService.UpdateTableCols(sysMenuTableCols);
        }

        /// <summary>
        /// 根据菜单id和字段名称获取数据列
        /// </summary>
        /// <param name="menuId">菜单id</param>
        /// <param name="fieldEnName">字段名称</param>
        /// <returns>返回数据列</returns>
        [HttpGet]
        public ReceiveStatus<SysMenuTableCols> GetTableColsByMenuIdOrFieldName(string menuId, string fieldEnName)
        {
            return _sysMenuTableColsService.GetTableColsByMenuIdOrFieldName(menuId, fieldEnName);
        }
        #endregion

    }
}
